package com.dcw.lixb.designmode.temp;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Stack;

/**
 * @author lixiaobin
 * @date 2020-07-20 16:45:24
 * @desc 描述信息
 */
public class TempMain {
    static int[] tags = {1,2,3,4};
    static int[] values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

    public static void main(String[] args) {
        Stack<Card> cards = new Stack<>();
        for (int i = 0; i < tags.length; i++) {
            for (int j = 0; j < values.length; j++) {
                cards.add(new Card(tags[i],values[j]));
            }
        }
        cards.add(new Card(0,14));
        cards.add(new Card(0, 15));

        Collections.shuffle(cards);
        CardPlayer player1 = new CardPlayer();
        CardPlayer player2 = new CardPlayer();
        CardPlayer player3 = new CardPlayer();

        int count = 0;
        while (cards.size() > 3) {
            if (count % 3 == 0) {
                player1.add(cards.pop());
            } else if (count % 3 == 1) {
                player2.add(cards.pop());
            } else if (count % 3 == 2) {
                player3.add(cards.pop());

            }
            count++;
        }

        System.out.println("player1 : "+player1);
        System.out.println("player2 : "+player2);
        System.out.println("player3 : "+player3);
        System.out.println("底牌:"+cards);
    }


    public static class CardPlayer{
        private List<Card> mCards = new ArrayList<>();

        public void add(Card card) {
            mCards.add(card);
            Collections.sort(mCards);
        }

        public void remove(Card card) {
            mCards.remove(card);
            Collections.sort(mCards);
        }

        public void addAll(List<Card> cards) {
            mCards.addAll(cards);
            Collections.sort(mCards);
        }

        public void clearAll() {
            mCards.clear();
        }

        @Override
        public String toString() {
            return "CardPlayer{" +
                    "mCards=" + mCards +
                    '}';
        }
    }


    public static class Card implements Comparable<Card> {
        int tag;
        int value;

        public Card(int tag, int value) {
            this.tag = tag;
            this.value = value;
        }

        @Override
        public String toString() {
            String tagStr = getTagStr(tag);
            String valueStr = getValueStr(value);
            return tagStr+valueStr;
        }

        private String getValueStr(int value) {
            switch (value) {
                case 11:
                    return "J";
                case 12:
                    return "Q";
                case 13:
                    return "K";
                case 14:
                    return "小王";
                case 15:
                    return "大王";
            }
            return String.valueOf(value);
        }

        private String getTagStr(int tag) {
            switch (tag) {
                case 1:
                    return "红桃";
                case 2:
                    return "黑桃";
                case 3:
                    return "方块";
                case 4:
                    return "梅花";
            }
            return "";
        }

        @Override
        public int compareTo(Card o) {
            return value!=o.value?value-o.value:tag-o.tag;
        }
    }
}
